# Copyright (c) 2020 Presto Labs Pte. Ltd.
# Author: donggu

import toml


class SymbologyInfo(object):
  def __init__(self):
    with open('data/coin2/symbology/translation.toml') as f:
      self.translation_per_mea = toml.load(f)
    with open('data/coin2/symbology/universe.toml') as f:
      self.universe_per_me = toml.load(f)

  def currency_list(self, me):
    return self.universe_per_me[me]['currencies']

  def product_list(self, me):
    return self.universe_per_me[me]['products']

  def norm_to_native_currency(self, mea, c):
    t = self.translation_per_mea[mea]
    if c in t['currencies']:
      c = t['currencies'][c]

    if t['native_currency_lower_case']:
      c = c.lower()
    return c

  def native_to_norm_currency(self, mea, c):
    t = self.translation_per_mea[mea]
    c = c.upper()
    if 'currencies' in t:
      for (k, v) in t['currencies'].items():
        if c == v:
          c = k
          break
    return c
